﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Utils.ControlToLoad;
using Utils.Exceptions;
using DAL;


namespace Prototype1
{
    public partial class ControlTemplateSimple : System.Web.UI.UserControl, IControlToLoadW
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region IControlToLoadW Members


        public Guid Id
    {
        get {
            if (ViewState["Id"] != null)
                return (Guid)ViewState["Id"];
            else
                throw new ValueNotAvailableException();
        }
        set { ViewState["Id"] = value; }
    }

        public void Save()
        {
            ExpenseTypeSimple exp = new ExpenseTypeSimple();
            exp.Id = this.Id;
            using (DataAccessDataContext dc = new DataAccessDataContext())
            {
                dc.ExpenseTypeSimples.InsertOnSubmit(exp);
                dc.SubmitChanges();
            }
        }

        public void Bind(Guid Id)
        {
            this.Id = Id;
        }

        #endregion
    }
}